package com.flower.controller;
/**
 * 后台管理模块——人员管理
 */
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.flower.pojo.Admin;
import com.flower.pojo.User;
import com.flower.service.IAdminService;
import com.flower.service.IUserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Controller
public class ManagePersonController {
	@Resource(name="userService")
	private IUserService iUserService;
	@Resource(name="adminService")
	private IAdminService iAdminService;
	
	/**
	 * 修改管理员密码
	 */
	@RequestMapping("/updatePassword.do")
	@ResponseBody
	public String updatePassword(HttpServletRequest request, Admin admin){
		//System.out.println(admin);
		int row = iAdminService.updateAdmin(admin);
		if(row > 0){
			request.getSession().setAttribute("ADMIN", admin);
			return "OK";
		}else{
			return "FAIL";
		}
	}
	
	/**
	 * 会员管理
	 */
	@RequestMapping("/selectAllUser.do")
	public String selectAllProduct(@RequestParam(required=true, defaultValue="1") Integer startPage,
			Model model, HttpServletRequest request){
		PageHelper.startPage(startPage, 10);
		List<User> users = iUserService.findAllUsers();
		PageInfo<User> pi = new PageInfo<>(users);
		model.addAttribute("PAGE", pi);
		//request.getSession().setAttribute("PAGE", pi);
		model.addAttribute("USERS", users);
		//request.getSession().setAttribute("USERS", users);
		//System.out.println(users);
		
		//return "redirect:/show_users.jsp";
		return "show_users";
	}
}
